package com.lesama.method;

public class ThreadNameDemo2 {
    public static void main(String[] args) {
        MyRunnable mr1 = new MyRunnable();
        MyRunnable mr2 = new MyRunnable();

        Thread t1 = new Thread(mr1);
        Thread t2 = new Thread(mr2);
        t1.setName("线程A");
        t2.setName("线程B");
        t1.start();
        t2.start();
        for (int i = 0; i < 2000; i++) {
            System.out.println(Thread.currentThread().getName() + "执行了" + i);
        }
    }
}

class MyRunnable implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 2000; i++) {
            System.out.println(Thread.currentThread().getName() + "执行了" + i);
        }
    }
}
